﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.Core;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;

namespace ZhouYu.DreamTour.DAL.Repository
{
    public class HotelRepository:IHotelRepository
    {
        /// <summary>
        /// 获取酒店页面信息
        /// </summary>
        /// <returns></returns>
        public List<Hotel> GetHotelsInfo()
        {
            //sql语句
            string sql = "SELECT * from Hotel";
            sql += " limit 0,5";
            //调用查询集合方法
            List<Hotel> hotellist = DapperHelper<Hotel>.QueryList(sql, null);
            return hotellist;
        }


        /// <summary>
        /// 获取酒店页面图片信息
        /// </summary>
        /// <returns></returns>
        public List<HotelDetails> GetHotelsPicInfo()
        {
            //sql语句
            string sql = "SELECT * from HotelDetails";           
            //调用查询集合方法
            List<HotelDetails> hoteldetaillist = DapperHelper<HotelDetails>.QueryList(sql, null);
            return hoteldetaillist;
        }        


        /// <summary>
        /// 根据Id获取酒店详情信息
        /// </summary>
        /// <returns></returns>
        public HotelDetailsRelation GetHotelDetailInfoById(int HotelId)
        {
            //sql语句
            string sql = "SELECT a.HotelId,a.HotelName,a.Hotel_Tel,a.`Describe`,b.HotelAddress,b.NumberOfRooms,b.Hotel_SmallPic from  hotel as a INNER JOIN hoteldetails as b ON a.HotelId = b.HotelId where a.HotelId=@HotelId";
            //创建酒店详情关联类对象
            HotelDetailsRelation hotelDetailsRelation = new HotelDetailsRelation();
            hotelDetailsRelation.HotelId = HotelId;
            //调用查询方法            
            return DapperHelper<HotelDetailsRelation>.QuerySingleOrDefault(sql, hotelDetailsRelation);
        }



        /// <summary>
        /// 获取酒店名称集合
        /// </summary>
        /// <returns></returns>
        public List<Hotel> GetHotelNameList()
        {
            //sql语句
            string sql = "select * from Hotel";
            //调用查询集合方法
            List<Hotel> hotellist = DapperHelper<Hotel>.QueryList(sql, null);
            return hotellist;
        }


        /// <summary>
        /// 根据酒店Id获取房间类型
        /// </summary>
        /// <returns></returns>
        public List<RoomInfo> GetRoom_TypeByHotelId(int HotelId)
        {
            //sql语句
            string sql = "SELECT Room_Id,Room_Type FROM roominfo WHERE HotelId=@HotelId";
            //创建房间信息对象
            RoomInfo roomInfo = new RoomInfo();
            roomInfo.HotelId = HotelId;
            //调用查询集合方法
            List<RoomInfo> roominfolist = DapperHelper<RoomInfo>.QueryList(sql,roomInfo);
            return roominfolist;
        }



        /// <summary>
        /// 添加酒店预定信息
        /// </summary>
        /// <returns></returns>+
        public int AddHotelOrderInfo(HotelOrder hotelOrder)
        {           
            //sql语句
            string sql = @"INSERT INTO HotelOrder(HotelId,User_Id,User_Name,Telphone,IdCard,Room_Id,RoomInto_Number,IntoTime,OutTime,SpecialRequest,HotelOrder_CreateTime,HotelOrder_UpdateTime)
                            VALUES(@HotelId,@User_Id,@User_Name,@Telphone,@IdCard,@Room_Id,@RoomInto_Number,@IntoTime,@OutTime,@SpecialRequest,@HotelOrder_CreateTime,@HotelOrder_UpdateTime)";
            //给创建时间和修改时间赋值
            hotelOrder.HotelOrder_CreateTime = DateTime.Now;
            hotelOrder.HotelOrder_UpdateTime = DateTime.Now;
            //调用添加方法
            return DapperHelper<HotelOrder>.Execute(sql, hotelOrder);
        }
        

        /// <summary>
        /// 根据酒店Id查询酒店信息
        /// </summary>
        /// <returns></returns>+
        public Hotel CheckInfoByHotelId(int HotelId)
        {
            //sql语句
            string sql = @"select * from Hotel where HotelId=@HotelId";
            //创建酒店预定对象
            Hotel hotel = new Hotel();
            hotel.HotelId = HotelId;
            //调用查询方法
            return DapperHelper<Hotel>.QuerySingleOrDefault(sql,hotel);
        }


        /// <summary>
        /// 根据酒店Id查询酒店图片
        /// </summary>
        /// <returns></returns>+
        public HotelDetails CheckHotelPicByHotelId(int HotelId)
        {
            //sql语句
            string sql = @"select Hotel_BigPic from HotelDetails where HotelId=@HotelId";
            //创建酒店预定对象
            HotelDetails hotelDetails = new HotelDetails();
            hotelDetails.HotelId = HotelId;
            //调用查询方法
            return DapperHelper<HotelDetails>.QuerySingleOrDefault(sql,hotelDetails);
        }



        /// <summary>
        /// 根据房间Id获取房间价格
        /// </summary>
        /// <returns></returns>
        public RoomInfo GetRoom_PriceByRoom_Id(int Room_Id)
        {
            //sql语句
            string sql = "SELECT Room_Price FROM roominfo WHERE Room_Id=@Room_Id";
            //创建房间信息对象
            RoomInfo roomInfo = new RoomInfo();
            roomInfo.Room_Id = Room_Id;
            //调用查询方法
            return DapperHelper<RoomInfo>.QuerySingleOrDefault(sql, roomInfo);           
        }


        #region 添加酒店订单信息
        /// <summary>
        /// 添加酒店订单信息
        /// </summary>
        /// <param name="TourId"></param>
        /// <returns></returns>
        public int AddOrderInfo(OrderInfo orderInfo)
        {
            //sql语句
            string sql = @"INSERT INTO orderinfo(Order_No,User_Id,Orde_PictureUrl,Order_ProInfo,Order_Money,Order_ReserveTime,ModifiedTime,Order_Content,Order_Name,Order_Type,Order_Status,Order_OutingTime)
                           VALUES(@Order_No,@User_Id,@Orde_PictureUrl,@Order_ProInfo, @Order_Money,@Order_ReserveTime, @ModifiedTime, @Order_Content,@Order_Name,'酒店',0,@Order_OutingTime)";
            //给预定时间和修改时间赋值
            orderInfo.Order_ReserveTime = DateTime.Now;
            orderInfo.ModifiedTime = DateTime.Now;
            //orderInfo.Order_OutingTime = DateTime.Now.AddDays(5);
            //调用添加方法
            return DapperHelper<OrderInfo>.Execute(sql, orderInfo);
        }
        #endregion


        /// <summary>
        /// 根据酒店Id获取酒店名称
        /// </summary>
        /// <returns></returns>
        public string GetHotelName(int hotelId)
        {
            //sql语句
            string sql = "select * from Hotel where HotelId=@HotelId";
            //创建酒店对象
            Hotel hotel = new Hotel();
            hotel.HotelId = hotelId;
            //调用查询集合方法
            return DapperHelper<Hotel>.QuerySingleOrDefault(sql,hotel).HotelName;
        }      
    }
}
